package com.hk.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.hk.model.CustUserDto;
import com.hk.model.ICustUserService;

public class CustUserUpdateController extends SimpleFormController {

	private ICustUserService custUserService;
		
	public void setCustUserService(ICustUserService custUserService) {
			this.custUserService = custUserService;
	}
	
	public CustUserUpdateController() {
		this.setCommandClass(CustUserDto.class);
		this.setCommandName("custupdate");
		this.setFormView("custuserupdate");
	}

	@Override
	public ModelAndView onSubmit(Object command) throws Exception {
		CustUserDto custdto=(CustUserDto)command;
		int count=custUserService.updateCustUser(custdto);
		ModelAndView mav=new ModelAndView();
		mav.setViewName("redirect:/custuserdetail.do?id="+custdto.getId());
		return mav;
	}

	@Override
	public Map referenceData(HttpServletRequest request) throws Exception {
		String id=request.getParameter("id");
		CustUserDto cust= custUserService.getCustUser(id);
		Map<String, CustUserDto> map =new HashMap<String, CustUserDto>();
		map.put("cust", cust);
		return map;
	}
}//
